.\"                                                               -*-nroff-*-
.\" Copyright (c) 2016-2021  Joachim Wiberg <troglobit@gmail.com>
.\"
.\" Permission to use, copy, modify, and/or distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd Apr 19, 2021
.Dt WATCHDOGCTL 1 SMM
.Os
.Sh NAME
.Nm watchdogctl
.Nd Status and control tool for watchdogd
.Sh SYNOPSIS
.Nm
.Op Fl hvV
.Op Fl c Ar CODE
.Op Fl p Ar PID
.Op clear
.Op disable | enable
.Op debug
.Op loglevel Ar LEVEL
.Op reload
.Op reset Oo MSEC Oc Oo MSG Oc
.Op fail Oo MSEC Oc Oo MSG Oc
.Op status
.Op test Op TEST
.Sh DESCRIPTION
.Nm
provides a safe way of querying status and controlling 
.Xr watchdogd 8 .
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl c, -code Ar CODE
Reset reason codes for fail command:
.Pp
.Bl -tag -width 99 -compact -offset indent
.It Cm 1
System OK
.It Cm 2
PID failed subscribing
.It Cm 3
PID failed kick
.It Cm 4
PID failed unsubscribing
.It Cm 5
PID failed to meet its deadline
.It Cm 6
Forced reset
.It Cm 7
Failed, unknown
.It Cm 8
File descriptor leak
.It Cm 9
Memory leak
.It Cm 10
CPU overload
.El
.Pp
Codes can also be listed at runtime with:
.Fl c Ar help
.It Fl h, -help
Show help message.
.It Fl p, -pid Ar PID
PID to use for fail and reset command.
.It Fl v, -verbose
Enable verbose mode, otherwise commands are silent.
.It Fl V, -version
Show version information.
.El
.Sh COMMANDS
Short forms of the below commands are allowed, as long as it is unique.
.Bl -tag -width Ds
.It Cm clear
Clear reset reason.
.It Cm counter
Show reset counter, number of reboots since power-on.
.It Cm debug
Toggle daemon debug log level.  See also the
.Cm loglevel
command.
.It Cm disble | enable
Temporarily disable, or enable, daemon.
.It Cm loglevel Ar LEVEL
Adjust daemon log level: none, err, warn,
.Ar notice ,
info, debug.
.\" Change daemon log level, see also
.\" .Cm debug .
.It Cm reload
Reload daemon configuration file, like sending SIGHUP, but the command
does not return until
.Nm watchdogd
has completed.
.It Cm reboot Oo MSEC Oc Oo MSG Oc
Alias to
.Cm reset .
.It Cm reset Oo MSEC Oc Oo MSG Oc
Perform system reset, with an optional millisecond delay and an optional
message to be stored as the reset reason label (usually process name).
A zero
.Ar MSEC
argument is the same as omitting the argument, leading to an immediate
reset.  On systems with
.Xr finit 8 ,
.Nm watchdogd
will ask Finit to do an orderly shutdown (stop services, sync and
unmount all file systems) before performing the WDT reset.
.It Cm fail Oo MSEC Oc Oo MSG Oc
Like the
.Cm reset
command, records reset reason (see above
.Fl c CODE )
but does not reboot unless
.Ar MSEC
is given.  I.e., omitting the
.Ar MSEC
argument does not have the same effect as in the
.Cm reset
command.
.It Cm status
Query status of daemon and show last reset reason, default command.
.It Cm test Op TEST
Run built-in tests of process supervisor functionality in daemon.  These
tests can be disabled at build time, so they may not be available in the
installed
.Nm .
The default test, if none is selected, runs the complete cycle.  You may
want to run these tests with the
.Fl -verbose
option to enable output.
.Pp
.Bl -tag -width false-unsubscribe -compact -offset indent
.It Cm complete-cycle
Verify subscribe, kick, and unsubscribe (no reset)
.It Cm disable-enable
Verify WDT disable, and re-enable (no reset)
.It Cm premature-trigger
Verify no premature trigger before unsubscribe (no reset)
.It Cm no-kick
Verify reset on missing first kick (reset)
.It Cm false-ack
Verify reset on invalid ACK in first kick (reset)
.It Cm failed-kick
Verify reset on invalid ACK in second kick (reset)
.It Cm false-unsubscribe
Verify unsubscribe with invalid ACK (reset)
.El
.It Cm version
Show program version.
.El
.Sh FILES
.Bl -tag -width /run/watchdogd.status -compact
.It Pa /etc/watchdogd.conf
Daemon configuration file. Read once when starting up and on SIGHUP or
.Cm reload
command.
.It Pa /run/watchdogd.status
Read to present WDT status and reset reason
.It Pa /run/watchdogd.sock
Used to connect to
.Nm watchdogd
.El
.Sh SEE ALSO
.Xr watchdogd 8
.Xr watchdogd.conf 5
.Sh AUTHORS
.Nm watchdogd
is an improved version of the original, created by Michele d'Amico and
adapted to uClinux-dist by Mike Frysinger.  It is maintained by Joachim
Wiberg at
.Lk https://github.com/troglobit/watchdogd "GitHub" .
